package org.hhchat.leetcode.tree;


public class code116 {
    /**
     * Created by HMH on 2017/3/29.
     */

    class TreeLinkNode {
        int val;
        TreeLinkNode left, right, next;
        TreeLinkNode(int x) { val = x; }
    }

    public class Solution {
        public void connectChild(TreeLinkNode left, TreeLinkNode right) {
            left.next=right;
            right.next = null;
            if (left.right != null) {
                left.right.next = right.left;
                connectChild(left.left,left.right);
                connectChild(right.left,right.right);
            }
        }

        public void connect(TreeLinkNode root) {
            if (root.left != null) {
                connectChild(root.left,root.right);
            }
        }
    }
}
